define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template','form'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template,Form) {

    var Controller = {
        index: function () {
            // 基于准备好的dom，初始化echarts实例
            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '电厂日耗图',
                    subtext: '电厂日耗图-1'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: [__('Xieche'), __('Rihao')]
                },
                toolbox: {
                    show: true,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Orderdata.column
                },


                yAxis:  [
                    {
                        type : 'value',
                        axisLabel : {
                            formatter: ''
                        }
                    }
                ],
                grid: [{
                    left: 'left',
                    top: 'top',
                    right: '10',
                    bottom: 30
                }],
                series: [{
                    name: __('Rihao'),
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Orderdata.paydata
                },
                    {
                        name: __('Xieche'),
                        type: 'line',
                        smooth: true,
                        areaStyle: {
                            normal: {}
                        },
                        lineStyle: {
                            normal: {
                                width: 1.5
                            }
                        },
                        data: Orderdata.createdata
                    }  ]

                ,type:'line'
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);




            $(window).resize(function () {
                myChart.resize();
            });




            $(document).on("click", "#dosubmit", function () {

                //alert("69");

                var fdata = $("#fayun-form").serialize();

                var riqi = [];    //类别数组（实际用来盛放X轴坐标值）
                var dianjia = [];    //销量数组（实际用来盛放Y坐标值）
                var series=[]; //用来存放坐标线
                var legend=[];

                $.ajax({
                    type: "post",
                    async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                    url:data_url,    //请求发送到TestServlet处
                    data: fdata,
                    dataType: "json",        //返回数据形式为json
                    success: function (result) {
                        //请求成功时执行该函数内容，result即为服务器返回的json对象
                        if(result.code==0)
                        {
                            Toastr.error(result.msg);
                            return;
                        }
                        if (result) {
                            for (var i = 0; i < result.riqi.length; i++) {
                                riqi.push(result.riqi[i]);    //挨个取出类别并填入类别数组
                            }



                            for(var n=0;n<result.series.length;n++)
                            {

                                var backdata=result.series[n];
                               var item= {name: '', type: 'line', smooth: true, areaStyle: {normal: {}},
                                    lineStyle: {normal: {width: 1.5}}, data:[]};

                               item.name=backdata.name;
                               item.data=backdata.lstdata;
                                series.push(item);
                                legend.push(backdata.name);
                            }



                            myChart.hideLoading();    //隐藏加载动画
                            myChart.setOption({        //加载数据图表
                                legend: {
                                    data: legend
                                },

                                xAxis: {
                                    data: riqi
                                },
                                series:series
                            });

                        }

                    },

                    error: function (errorMsg) {
                        //请求失败时执行该函数
                        Toastr.error(ret.msg);
                        myChart.hideLoading();
                    }

                });
            });


            $("form").submit(function (e) {

                alert("111");
                e.preventDefault();
            });








            Controller.api.bindevent();

        }



        ,api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },


        showcharts:function qiye(is_add) {

            Layer.load();

        }


    };





    return Controller;
});